package com.zxp.mybatis.dao;

import com.zxp.mybatis.bean.Lable;
import com.zxp.mybatis.pojo.Page;
import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 二级缓存： 默认readWrite = true,即为对象拷贝，对象model需要可序列化, 改为readWrite = false,则缓存为引用，会有安全问题
 * @author zxp
 * @date 2021-08-20 16:59
 */
@CacheNamespace(readWrite = true)
public interface LableMapper {

    @Select("select * from t_lable where id=#{id}")
    Lable getById(Integer id);

    @Select("select * from t_lable where id=#{id}")
    Lable getById2(Integer id);

    @Select("select * from t_lable")
    List<Lable> page(Page page);

    @Select("select * from t_lable")
    List<Lable> page2(String name,Page page);

    @Update("update t_lable set name=#{name} where id=#{id}")
    int updateById(Lable lable);

    // sql实质上是查询，但加了增删改的注解的话，也会让一级缓存失效
    @Update("select * from t_lable where id=#{id}")
    int updateById2(Lable lable);

    int updateById3(Lable lable);
}
